package ipad.asia.service.enterprise;

import ipad.asia.entity.Enterprise;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Component
@FeignClient(value = "PROVIDER-ENTERPRISE")
public interface EnterpriseFeign {
    /**
     * 登录说明：
     * 3是表示封号，禁止登录，跳转到申请解锁页面
     * 2表示严重警告！需要处理被举报的东西
     * 1表示举报，警告你不要再犯错误
     * 4表示可以正常登录
     * 0表示账号密码错误
     * @param user
     * @param password
     * @return
     * @throws IOException
     */
    @PostMapping("/enterprise/login")
     int login(@RequestParam("user") String user, @RequestParam("password") String password);

    /**
     * 注册，true为注册成功，false为注册失败用户存在或者非法输入
     * @param user
     * @param password
     * @return
     */
    @RequestMapping ("/enterprise/register/")
     boolean register(@RequestParam(value = "user",required = false) String user,
                           @RequestParam(value = "password", required = false) String password,
                           @RequestParam(value = "email",required = false) String email,
                           @RequestParam(value = "phone",required = false) String phone,
                           @RequestParam(value = "shopName",required = false) String shopName,
                           @RequestParam(value = "credentials",required = false) String credentials,
                           @RequestParam(value = "address",required = false) String address);

    /**
     * 存到session或者查找id
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping("/enterprise/get/{id}")
     Enterprise get(@PathVariable("id") int id) throws Exception;

    @RequestMapping("/enterprise/getName")
     Enterprise getName(@RequestParam(value = "user",required = false) String user) ;

    /**
     * 更新个人信息
     * @param user
     * @param phone
     * @param email
     * @param sex
     * @param address
     * @param credentials
     * @param password
     */
    @Transactional
    @RequestMapping(value = "/enterprise/updateInfo")
     void updateInfo( @RequestParam(value = "user",required = false)String user,
                            @RequestParam(value = "phone",required = false) String phone,
                            @RequestParam(value = "email",required = false) String email,
                            @RequestParam(value = "sex",required = false) String sex,
                            @RequestParam(value = "address",required = false) String address,
                            @RequestParam(value = "credentials",required = false) String credentials,
                            @RequestParam(value = "password",required = false) String password);

    @RequestMapping("/enterprise/findAll")
     List<Enterprise> findAll();

}
